import request from "@/utils/request";

import {AddressForm, AddressQuery} from "./types";

const baseUri = "/mv1/api/lou-ddress";

/**
 * 获取用户分页列表
 *
 * @param query
 */
export function getAddressList(query: AddressQuery) {
  return request({
    url: baseUri + "/",
    method: "get",
    params: query,
  });
}

/**
 *
 */
export function getAddressDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
  });
}

/**
 * 分配菜单权限给角色
 *
 * @param queryParams
 */
export function update(roleId: number, data: AddressForm) {
  return request({
    url: baseUri + "/auth_menu/" + roleId,
    method: "put",
    data: {
      menuIds: data,
    },
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addAddress(data: AddressForm) {
  return request({
    url: baseUri + "/edit",
    method: "post",
    data: data,
  });
}

/**
 * 更新
 *
 * @param id
 * @param data
 */
export function updateAddress(id: number, data: AddressForm) {
  return request({
    url: baseUri + "/edit/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 批量删除角色，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteAddress(id: number) {
  return request({
    url: baseUri + "/" + id,
    method: "delete",
  });
}

/**
 * 导入用户
 *
 * @param file
 */
export function importUser(deptId: number, file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: baseUri + "/import",
    method: "post",
    params: {deptId: deptId},
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 导入地址
 * @param type
 * @param file
 */
export function importAddress(type: number, file: File) {
  const formData = new FormData();
  formData.append("file", file);

  return request({
    url: baseUri + "/import",
    method: "post",
    params: { type: type },
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
